package com.gitee.wsl.compose.modifier.animate

import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.foundation.background
import androidx.compose.material3.LocalContentColor
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.graphicsLayer
import com.gitee.wsl.compose.modifier.ModifierAnimateScope


@Composable
internal fun Modifier.fade(enable: Boolean): Modifier {
    val alpha by animateFloatAsState(if (enable) 0.5f else 1.0f)
    return this then Modifier.graphicsLayer { this.alpha = alpha }
}

@Composable
fun ModifierAnimateScope.fade(enable: Boolean){
    modifier = modifier.fade(enable)
}

@Composable
internal fun Modifier.fadedBackground(): Modifier {
    val color = LocalContentColor.current
    return this then Modifier.background(color.copy(alpha = 0.5f))
}

@Composable
fun ModifierAnimateScope.fadedBackground(){
    modifier = modifier.fadedBackground()
}